package edu.sctu.zhuyingzhi.month201506.day20150616.httpTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by user13 on 2015/6/16.
 */
public class HttpRequest {

    public static String getSend(String url) throws IOException {
        String result = "";
        BufferedReader in = null;

        URL readUrl = new URL(url);
        URLConnection urlConnection = readUrl.openConnection();
        urlConnection.setRequestProperty("accept", "*/*");
        urlConnection.setRequestProperty("connection", "Keep-Alive");
        urlConnection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");

        urlConnection.connect();

        Map<String,List<String>> map = urlConnection.getHeaderFields();
        for (String key:map.keySet()){
            System.out.println(key+"----->"+map.get(key));
        }
        in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

        String line;
        while((line = in.readLine()) != null){
            result += line;
        }

            if (in != null){
                in.close();
            }
        return result;
    }



}
